﻿using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Xml;

namespace T.FAS.Runtime.DataAccess.SQLDom
{
    /// <summary>
    /// 排序子项类
    /// </summary>
    /// <remarks>SQL语句中的排序子项</remarks>
    public class OrderByField : Field
    {
        #region 常量

        /// <summary>
        /// Insert语句中的插入字段常量
        /// </summary>
        public const string ORDERBY = "OrderByType";

        #endregion

        #region 字段


        #endregion

        #region 构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        public OrderByField(OrderByType orderByType = OrderByType.Asc)
            : base()
        {
            this.OrderByType = orderByType;
            base.CreateChildCollection();
        }

        #endregion

        #region 属性

        public OrderByType OrderByType { get; set; }
        #endregion

        #region 方法

        #endregion

        /// <summary>
        /// 克隆
        /// </summary>
        /// <returns>左连接子项类</returns>
        public override object Clone()
        {
            var newItem = base.Clone() as OrderByField;

            newItem.OrderByType = this.OrderByType;

            return newItem;
        }

        /// <summary>
        /// 转换成SQL
        /// </summary>
        /// <returns>SQL</returns>
        public override string ToSQL()
        {
            StringBuilder result = new StringBuilder();

  
            result.Append(base.ToSQL());
            result.Append(this.OrderByType == OrderByType.Desc ? " DESC " : " ASC ");

            return result.ToString();
        }

         
    }

    
}
